<?php
  require_once('tpl/header.php');
?>
<?php 
require_once('../system/loginCheck.php');
    require_once('../system/dbConn.php');
connect();
    ?>
    <h1>欢迎管理员<?php echo $_SESSION["adminname"]; ?>使用本系统</h1>
    <?php
    $videoname=$_POST["videoname"];
    $videotype=$_POST["videotype"];
    $intro=$_POST["intro"];
    $address=$_POST["address"];
    //var_dump($_POST);
    //var_dump($_FILES);
    //文件上传
    if ($_FILES["pic"]["error"]) {
        switch ($_FILES["pic"]["error"]) {
            case '1':
                echo "文件尺寸超过了配置文件的最大值";
                # code...
                break;
            case '3':
                echo "部分文件上传";
                # code...
                break;
            case '4':
                echo "没有文件上传";
                # code...
                break;
            
            default:
                # code...
                break;
        }
        # code...
    }
    $arr=explode(".",$_FILES["pic"]["name"]);
    $suffix=$arr[count($arr)-1];
    //判定文件类型是不是图片
    $allowtype=array("jpg","jpeg","png","PNG","JPG","JPEG","Bmp","gif");
    if (!in_array($suffix, $allowtype)) {
        //扩展名不在xx中
        //echo "文件上传错误";
        //exit;//脚本退出结束
        die("文件上传错误");

    }
    //拷贝,文件命名使用系统时间加三位随机数命名
    
    $filePath="../posters/";
   
    $randname=date("YmdHis").rand(100,999).".".$suffix;
   if (move_uploaded_file($_FILES["pic"]["tmp_name"], $filePath.$randname)) {
        # code...
    echo "海报上传成功"."<br>";
  }
  //取管理员的adminid
  $uploadadmin=$_SESSION["adminid"];
  //sql语句
  $sql="insert into videos values(null,'$videoname',$videotype,'$randname','$intro',now(),$uploadadmin,0,0,'$address')";
  $result=mysql_query($sql);
  if ($result==1) {
    echo "视频添加成功，3s后返回添加页面";
    header("refresh:3;url='videoAdd.php'");
  }
  else
    echo "添加失败";

     ?>

   


<?php
  require_once('tpl/footer.php');
?>